package uumoi

class Channel {
	String name
	String description

	Language language

	static belongsTo = [account: Account]
	static hasMany = [regions: Region, brands: Brand]

	static constraints = {
		description nullable: true
	}

	static findByRegionAndBrand(Region region, Brand brand) {
		return executeQuery("select c from Channel c where :region in elements(c.regions) and :brand in elements(c.brands)", [region: region, brand: brand])
	}

	static canAccess(Long id, Account account) {
		return executeQuery("select c.id from Channel c where :id = c.id and :account = c.account", [id: id, account: account])
	}
}
